package com.igeek.boot.controller;

import com.igeek.boot.entity.ZhrjAlarmInfo;
import com.igeek.boot.result.EventDateDTO;
import com.igeek.boot.result.Result;
import com.igeek.boot.service.IZhrjAlarmInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author fengqq
 * @Description TODO
 * @Date 2024/8/23  11:21
 */
@RestController
@RequestMapping("/zhrj/events")
@Api(tags = "事件模块的控制层")
public class AlarmController {

    @Autowired
    private IZhrjAlarmInfoService zhrjAlarmInfoService;

    //事件分类查询
    @GetMapping("/statistic")
    @ApiOperation("事件分类查询")
    public Result eventStatistic(){
        Map<String,Object> map = zhrjAlarmInfoService.eventStatistic();
        return new Result(200,"查询成功",map);
    }

    //月度事件数量趋势 yyyy-MM
    @GetMapping("/month_date_count")
    @ApiOperation("月度事件数量趋势")
    public Result eventMonthCount(String datemonth){
        try{
            //获取年份 yyyy
            int year = Integer.parseInt(datemonth.substring(0, 4));
            int month = Integer.parseInt(datemonth.substring(5));
            //获取月份 MM
            List<EventDateDTO> list = zhrjAlarmInfoService.eventMonthCount(year,month);
            return new Result(200,"查询成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,"查询失败");
        }
    }


    //多表查询：根据部门和事件类型查询详情列表
    @GetMapping("/findAll")
    @ApiOperation("根据部门和事件类型查询详情列表")
    public Result findAllAlarmInfo(
            @RequestParam(value = "wanIp",required = false) String wanIp,
            @RequestParam(value = "deptId",required = false) Long deptId,
            @RequestParam(value = "eventType",required = false) Integer eventType){
        try{
            List<ZhrjAlarmInfo> list = zhrjAlarmInfoService.findAllAlarmInfo(wanIp,deptId,eventType);
            return new Result(200,"查询成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,"查询失败");
        }

    }















}
